package com.gitee.wsl.transform.encode

import com.gitee.wsl.transform.encode.sample.PunyCode
import kotlin.test.Test
import kotlin.test.assertEquals


class PunyCodeTest {
    @Test
    fun encodeDecodeTest() {
        val text = "Hutool编码器"
        val strPunyCode = PunyCode.encode(text)
        assertEquals("Hutool-ux9js33tgln", strPunyCode)
        var decode = PunyCode.decode("Hutool-ux9js33tgln")
        assertEquals(text, decode)
        decode = PunyCode.decode("xn--Hutool-ux9js33tgln")
        assertEquals(text, decode)
    }

    @Test
    fun encodeDecodeTest2() {
        // 无需编码和解码
        val text = "Hutool"
        val strPunyCode = PunyCode.encode(text)
        assertEquals("Hutool", strPunyCode)
    }

    @Test
    fun encodeEncodeDomainTest() {
        val domain = "赵新虎.中国"
        val strPunyCode = PunyCode.encodeDomain(domain)
        val decode = PunyCode.decodeDomain(strPunyCode)
        assertEquals(decode, domain)
    }

    @Test
    fun encodeEncodeDomainTest2() {
        val domain = "赵新虎.com"
        val strPunyCode = PunyCode.encodeDomain(domain)
        assertEquals("xn--efvz93e52e.com", strPunyCode)
        val decode = PunyCode.decodeDomain(strPunyCode)
        assertEquals(domain, decode)
    }

    @Test
    fun encodeEncodeDomainTest3() {
        val domain = "赵新虎.COM"
        val strPunyCode = PunyCode.encodeDomain(domain)
        assertEquals("xn--efvz93e52e.COM", strPunyCode)
        val decode = PunyCode.decodeDomain(strPunyCode)
        assertEquals(domain, decode)
    }
}
